package com.wx.house.common.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * 各种id生成策略
 * <p>Title: IDUtils</p>
 * <p>Description: </p>
 * @date 2015年7月22日下午2:32:10
 */
public class IDUtils {

/**
 * 生成uuid
 *
 * @return
 * @author jiangL
 * 2015-6-10-上午10:42:38
 */
public static String createUUId() {
	UUID uuid = UUID.randomUUID();
	return uuid.toString().replaceAll("-", "");
}

/**
 * 图片名生成
 */
public static String genImageName() {
	//取当前时间的长整形值包含毫秒
	long millis = System.currentTimeMillis();
	//long millis = System.nanoTime();
	//加上三位随机数
	Random random = new Random();
	int end3 = random.nextInt(999);
	//如果不足三位前面补0
	return millis + String.format("%03d", end3);
}

/**
 * id生成
 */
public static long genItemId() {
	//取当前时间的长整形值包含毫秒
	long millis = System.currentTimeMillis();
	//long millis = System.nanoTime();
	//加上两位随机数
	Random random = new Random();
	int end2 = random.nextInt(99);
	//如果不足两位前面补0
	String str = millis + String.format("%02d", end2);
	long id = new Long(str);
	return id;
}

/**
 * id生成-根据指定长度
 */
public static long genItemId(Integer len) {
	return new Long(getItemId().substring(getItemId().length() - len));
}

//生成字符串id
private static String getItemId() {
	//取当前时间的长整形值包含毫秒
	long millis = System.currentTimeMillis();
	//long millis = System.nanoTime();
	//加上两位随机数
	Random random = new Random();
	int end2 = random.nextInt(999);
	//如果不足两位前面补0
	return millis + String.format("%03d", end2);
}

public static String getSafeKey() {
	Random random = new Random();
	int r = random.nextInt(99999999);
	if (r < 10000000) r = r + 10000000;
	return Integer.toString(r);
}

public static Integer getIntegerSafeKey() {
	Random random = new Random();
	int r = random.nextInt(99999999);
	if (r < 10000000) r = r + 10000000;
	return r;
}

public static void main(String[] args) {
//	for (int i = 0; i < 100; i++)
//		System.out.println(genItemId());
////	for (int i = 0; i < 100; i++) {
////		System.out.println(getNumberId(19));
////	}
	
	System.out.println(createOrderNumber());
}

/**
 * @Description 19位数字id
 * @Param number
 * @Return java.lang.Long
 * @Author 罗棋
 * @Date 2019/07/11 下午 05:38
 */
public static Long getLongLongNumberId() {
	StringBuilder stringBuilder = new StringBuilder();
	Random random = new Random();
	
	for (int i = 0; i < 19; i++) {
		stringBuilder.append(random.nextInt(9));
	}
	Long result = Long.parseLong(stringBuilder.toString());
	if (result < 1111111111111111111L) {
		result = getLongLongNumberId();
	}
	return result;
}

public static String createOrderNumber() {
	return new SimpleDateFormat("yyMMddhhmmss").format(new Date());
}


}
